package view;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JTextField;

import javax.swing.WindowConstants;
import javax.swing.SwingUtilities;

import controller.Sistema;


/**
* This code was edited or generated using CloudGarden's Jigloo
* SWT/Swing GUI Builder, which is free for non-commercial
* use. If Jigloo is being used commercially (ie, by a corporation,
* company or business for any purpose whatever) then you
* should purchase a license for each developer using Jigloo.
* Please visit www.cloudgarden.com for details.
* Use of Jigloo implies acceptance of these licensing terms.
* A COMMERCIAL LICENSE HAS NOT BEEN PURCHASED FOR
* THIS MACHINE, SO JIGLOO OR THIS CODE CANNOT BE USED
* LEGALLY FOR ANY CORPORATE OR COMMERCIAL PURPOSE.
*/
public class AltaUsuario extends javax.swing.JFrame {
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	private AltaUsuario instancia; 
	private JLabel DNI;
	private JTextField jTextField_email;
	private JTextField jTextField_tel;
	private JTextField jTextField_dom;
	private JTextField jTextField_dni;
	private JTextField jTextField_ap;
	private JTextField jTextField_nom;
	private JLabel Email;
	private JLabel Telefono;
	private JButton Cancelar;
	private JButton Aceptar;
	private JLabel Domicilio;
	private JLabel Apellido;
	private JLabel Nombre;
	/**
	* Auto-generated main method to display this JFrame
	*/
	public static void main(String[] args) {
		SwingUtilities.invokeLater(new Runnable() {
			public void run() {
				AltaUsuario inst = new AltaUsuario();
				inst.setLocationRelativeTo(null);
				inst.setVisible(true);
			}
		});
	}
	
	public AltaUsuario() {
		super();
		initGUI();
		instancia=this;
		this.setTitle("Alta Usuario");
	}
	
	private void initGUI() {
		try {
			setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
			getContentPane().setLayout(null);
			{
				Nombre = new JLabel();
				getContentPane().add(Nombre);
				Nombre.setText("Nombre");
				Nombre.setBounds(18, 12, 100, 16);
			}
			{
				Apellido = new JLabel();
				getContentPane().add(Apellido);
				Apellido.setText("Apellido");
				Apellido.setBounds(18, 45, 100, 16);
			}
			{
				DNI = new JLabel();
				getContentPane().add(DNI);
				DNI.setText("DNI");
				DNI.setBounds(18, 80, 100, 16);
			}
			{
				Domicilio = new JLabel();
				getContentPane().add(Domicilio);
				Domicilio.setText("Domicilio");
				Domicilio.setBounds(18, 112, 100, 16);
			}
			{
				Telefono = new JLabel();
				getContentPane().add(Telefono);
				Telefono.setText("Telefono");
				Telefono.setBounds(18, 147, 100, 16);
			}
			{
				Email = new JLabel();
				getContentPane().add(Email);
				Email.setText("Email");
				Email.setBounds(18, 182, 100, 16);
			}
			{
				jTextField_nom = new JTextField();
				getContentPane().add(jTextField_nom);
				jTextField_nom.setBounds(142, 9, 191, 23);
			}
			{
				jTextField_ap = new JTextField();
				getContentPane().add(jTextField_ap);
				jTextField_ap.setBounds(142, 42, 191, 23);
			}
			{
				jTextField_dni = new JTextField();
				getContentPane().add(jTextField_dni);
				jTextField_dni.setBounds(142, 77, 191, 23);
			}
			{
				jTextField_dom = new JTextField();
				getContentPane().add(jTextField_dom);
				jTextField_dom.setBounds(142, 109, 191, 23);
			}
			{
				jTextField_tel = new JTextField();
				getContentPane().add(jTextField_tel);
				jTextField_tel.setBounds(142, 144, 191, 23);
			}
			{
				jTextField_email = new JTextField();
				getContentPane().add(jTextField_email);
				jTextField_email.setBounds(142, 179, 191, 23);
			}
			{
				Aceptar = new JButton();
				getContentPane().add(Aceptar);
				Aceptar.setBounds(70, 228, 88, 23);
				Aceptar.setText("Aceptar");
				Aceptar.addActionListener(new ActionListener() 
				{
					
					@Override
					public void actionPerformed(ActionEvent arg0) {
						if (HelperTest.validarUsuario(jTextField_dni.getText(),jTextField_nom.getText(),jTextField_ap.getText(),jTextField_dom.getText(), jTextField_tel.getText(), jTextField_email.getText())) {
							if  (Sistema.getInstance().altaUsuario(jTextField_dni.getText(),jTextField_nom.getText(),jTextField_ap.getText(),jTextField_dom.getText(), jTextField_tel.getText(), jTextField_email.getText())==false){
								HelperTest.showMessage("No se pudo dar de alta el usuario");
							}
							limpiarCampos();	
						}
					}
				});
			}
			{
				Cancelar = new JButton();
				getContentPane().add(Cancelar);
				Cancelar.setText("Cancelar");
				Cancelar.setBounds(182, 228, 88, 23);
				Cancelar.addActionListener(new ActionListener() {
					
					@Override
					public void actionPerformed(ActionEvent e) {
						Menu app = new Menu();
						app.setLocationRelativeTo(null);
						app.setVisible(true);
						instancia.dispose();
					}
				});
			}
			pack();
			this.setSize(404, 310);
		} catch (Exception e) {
		    //add your error handling code here
			e.printStackTrace();
		}
		
	}
	private void limpiarCampos() {
		jTextField_nom.setText("");
		jTextField_ap.setText("");
		jTextField_dni.setText("");
		jTextField_dom.setText("");
		jTextField_tel.setText("");
		jTextField_email.setText("");
		
	}
	

}
